package org.adl.registry.types;

/**
 *
 * @author Jacob Marks - Joint ADL Co-Lab
 * @version 1.0
 * @license This software is licensed as open source software pursuant to the terms defined in the Joint ADL Co-Lab Open Source Software License.  Use of any part of this software constitutes acceptance of this license. The Joint ADL Co-Lab open source agreement is available at {@link http://adlregistry.adlnet.gov/source_license.html}.
 */
public class Command extends RimParameter
{
    public static class Commands
    {
        public static final String SearchRequest = "searchrequest";
        public static final String RetrieveRequest = "retrieverequest";
        public static final String ProcessTransaction = "processtransaction";
        public static final String GetTransactionStatus = "gettransactionstatus";
        public static final String GetValidationStatus = "getvalidationstatus";
    }
    
    /**
     * Creates a new instance of Command
     */
    public Command(String iValue)
    {
        super("command", iValue);
        
        this.validate();
    }
    
    protected void validate()
    {
        String value = super.getParameterValue();
        
        boolean valid = false;
        
        if (value.equalsIgnoreCase(Commands.GetTransactionStatus))
        {
            valid = true;
        }
        else if (value.equalsIgnoreCase(Commands.GetValidationStatus))
        {
            valid = true;
        }
        else if (value.equalsIgnoreCase(Commands.ProcessTransaction))
        {
            valid = true;
        }
        else if (value.equalsIgnoreCase(Commands.RetrieveRequest))
        {
            valid = true;
        }
        else if (value.equalsIgnoreCase(Commands.SearchRequest))
        {
            valid = true;
        }
        
        if (valid == false)
        {
            super.getValidaionErrors().add("The command '" + super.getOrigionalValue() + "' is not a valid ADL Registry command.");
        }
    }
}
